﻿/********************************************************************
	日期:2022/03/27
	名称:LoginWnd
	邮箱:yunnibbd@163.com
	作者:yunni
	描述:登录界面逻辑
*********************************************************************/

using PEProtocol;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LoginWnd : WindowRoot{
    public InputField iptAcct;
    public InputField iptPass;
    public Button btnEnter;
    public Button btnNotice;

    protected override void InitWnd(){
        base.InitWnd();
        //获取本地存储的账号
        if (PlayerPrefs.HasKey("Acct") && PlayerPrefs.HasKey("Pass")){
            iptAcct.text = PlayerPrefs.GetString("Acct");
            iptPass.text = PlayerPrefs.GetString("Pass");
        }
        else{
            iptAcct.text = "";
            iptPass.text = "";
        }
    }

    /*
     * @brief 点击进入游戏
     */
    public void ClickEnterBtn(){
        audioSvc.PlayUIMusic(Constants.UILoginBtn);

        string _acct = iptAcct.text;
        string _pass = iptPass.text;
        if (_acct != "" && _pass != ""){
            //更新本地存储的账号密码
            PlayerPrefs.SetString("Acct", _acct);
            PlayerPrefs.SetString("Pass", _pass);

            //TODO 发送网络消息，请求登录
            GameMsg msg = new GameMsg{
                cmd = (int) CMD.ReqLogin,
                reqLogin = new ReqLogin{
                    acct = _acct,
                    pass = _pass
                }
            };
            netSvc.SendMsg(msg);
        }
        else{
            GameRoot.AddTips("账号或密码为空");
        }
    }

    public void ClickNoticeBtn(){
        audioSvc.PlayUIMusic(Constants.UIClickBtn);
        GameRoot.AddTips("功能正在开发");
    }
}